var forumNameExistFlag = false;
var trNodeTag;



function bindForumStatus() {
	var status = $("#hiddenForumNameQuery").val();
	$("#forumActiveQuery").val(status);
}

function searchForum() {
	document.frmListForum.action = "/EKMS-web/forum/visitForum.do?action=listForum";
	document.frmListForum.submit();
}

function resetForumSearch() {
	$("#forumNameQuery").attr("value", "");
	$("#forumActiveQuery").val("");
}

function sortForum(eventSrc) {
	//Set Sort Type according Link title
	var type = eventSrc.title;
	$("#sortType").val(type);
	//Set Sort Order
	var order = $("#sortOrder").val();
	if (order == "asce") {
		sortOrder = "desc";
		$("#sortOrder").val("desc");
	} else {
		sortOrder = "asce";
		$("#sortOrder").val("asce");
	}
	document.frmListForum.action = "/EKMS-web/forum/visitForum.do?action=listForum";
	document.frmListForum.submit();

}


function goToFirstPage(){
	$("input[name='targetPage']").val(1);
	goToPage();
}

function goToPreviousPage(){
	var now = $("input[name='nowPage']").val();
	var total = $("input[name='totalPage']").val();
	if(parseInt(now) - 1 >= 1){
		document.frmListForum.action = "/EKMS-web/forum/visitForum.do?action=goToPreviousPage";
		document.frmListForum.submit();
	}else{
		alert("This is the first page!");
	}
}

function goToPreviousPage(){
	var now = $("input[name='nowPage']").val();
	var total = $("input[name='totalPage']").val();
	if(parseInt(now) - 1 >= 1){
		document.frmListForum.action = "/EKMS-web/forum/visitForum.do?action=goToPreviousPage";
		document.frmListForum.submit();
	}else{
		alert("This is the first page!");
	}
}

function goToNextPage(){
	var now = $("input[name='nowPage']").val();
	var total = $("input[name='totalPage']").val();
	if(parseInt(now) +1 <= total){
		document.frmListForum.action = "/EKMS-web/forum/visitForum.do?action=goToNextPage";
		document.frmListForum.submit();
	}else{
		alert("This is the last page!");
	}
}

function goToLastPage(){
	var total = $("input[name='totalPage']").val();
	$("input[name='targetPage']").val(total);
	goToPage();
}

function goToPage(){
	var target = $("input[name='targetPage']").val();
	var total = $("input[name='totalPage']").val();
	if(typeof(target) != NaN && parseInt(target) > 0 && parseInt(target) <= parseInt(total) ){
		document.frmListForum.action = "/EKMS-web/forum/visitForum.do?action=goToTargetPage";
		document.frmListForum.submit();
	}else{
		alert("The page number must be a number and between 0 and "+ total + "!");
	}
}


function  check(field,limit)
{
  if (field.value.length >= limit)
    {
        field.value = field.value.substr(0,limit-1);
        field.focus();
     }
}



var message;


function resetForumControls(){
	$("input").attr('disabled',false);
	$("textarea").attr('disabled',false);
	$("select").attr('disabled',false);
	$("#loadingPic").hide();
}
//Post data to URL using method
function post_to_url(path, params, method) {

	// If not defined, use post as default
	method = method || "post";

	var form = document.createElement("form");
	form.setAttribute("method", method);
	form.setAttribute("action", path);

	for ( var key in params) {
		var hiddenField = document.createElement("input");
		hiddenField.setAttribute("type", "hidden");
		hiddenField.setAttribute("name", key);
		hiddenField.setAttribute("value", params[key]);
		form.appendChild(hiddenField);
	}

	document.body.appendChild(form);
	form.submit();
}
function showDetail(a){
	var id=parseInt(a.name);
	post_to_url('/EKMS-web/forum/visitForum/showForumDetails.do?action=listTopic', {'forumId' : id}, 'post');
}


function showTopicDetail(a) {
	var id = parseInt(a.name);
	post_to_url('/EKMS-web/forum/visitForum/showTopicDetails.do?action=listReply', {
		'topicId' : id
	}, 'post');
}




